<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>7.模拟一个数据监测</title>

</head>
<body>
    <script type="text/javascript">

        let data = {
            name: '尚硅谷',
            address: '北京'
        }

        //创建一个监视的实例对象,用于监视data中属性的变化
        var observer = new Observer(data);
        console.log(observer)

        //准备一个vm实例对象
        let vm = {}
        vm._data = data = observer;

        function Observer(data) {
            //汇总对象中所有的属性形成一个数组
            var keys = Object.keys(data);
            keys.forEach((key) => {
                Object.defineProperty(this, key, {
                    get() {
                        return data[key];
                    },
                    set(newValue) {
                        console.log(`${key}被改了,我要求解析模版,生成虚拟DOM..`)
                        data[key] = newValue;
                    }
                })
            })
        }

    </script>

</body>


</html>